package cs271.examples.oop;

/**
 * A typical, logical overloading of the .equals() method.
 * And an example of override the toString method.
 *
 * @author mbone
 */
public class OverrideEquals {

    public String myString;
    public int myInt;
    
    public boolean equals(Object obj) {
        if(obj instanceof OverrideEquals) {
            OverrideEquals objEquals = (OverrideEquals) obj;
            if(this.myString.equals(objEquals.myString) &&
               this.myInt == objEquals.myInt) {
                return true;
            }
        }
        return false;
    }
    
    public String toString() {
        return myString + " " + myInt;
    }
    
    
    public static void main(String[] args) {
        OverrideEquals e1 = new OverrideEquals(); 
        OverrideEquals e2 = new OverrideEquals();
        OverrideEquals e3 = new OverrideEquals();
        
        e1.myString = "Hello World";
        e2.myString = "Hello World";
        e3.myString = "Hello World";
        
        e1.myInt = 1;
        e2.myInt = 1;
        e3.myInt = 3;
        
        System.out.println(e1.equals(e2));
        System.out.println(e1.equals(e3));
        System.out.println(e1.equals(new String("Hello World")));
        
        System.out.println(e1);
        System.out.println(e2);
        System.out.println(e3);
    }
}
